﻿<%@ page language="C#" autoeventwireup="true" CodeFile="ImpMonitorIndex_SelTBS.aspx.cs" inherits="Topo_ImpMonitorIndex_SelTBS" enableEventValidation="false" %>
<%@ Register Assembly="NineRays.WebControls.FlyTreeView" Namespace="NineRays.WebControls"  TagPrefix="NineRays" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>重点基站选择</title>
    <link href="../App_Themes/CSS/default.css" rel="stylesheet" type="text/css" />
    <link href="../App_Themes/CSS/Topo/ImpMonitorIndexSelTBS.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript" language="javascript">

        //这里的代码，是此控件操作复选择框的，主要作用是当父结点被选择时，子结点根着对应变化
        var ignoreEvents = false;
        var countTemp = 0;
        var tree = null;
        var nodeNumber = 0; //节点数目
        var TBSID = [];
        var nodeTree;
        function flyNodeTree_onInitialized(treeviewObject) {
            nodeTree = treeviewObject;
        }
        function nodeEventHandler(treeview, node, eventType) {
            // debugger;
            if (!tree) {
                tree = treeview;
            }
            if (ignoreEvents) return;
            ignoreEvents = true;
            if (eventType == "checked") {
                nodeNumber = 0;
                setChildrenCheckBox(node, true);
                if (allSiblingChecked(node)) {

                }
                if (node.getChildNodes().length == 0) {
                }
            }

            else if (eventType == "unchecked") {
                setChildrenCheckBox(node, false);

                //setParentCheckBox(node, false);
            } else if (eventType == "expanded") {
                node.setImageUrl('../images/topo/operation/folder_open.gif');
            } else if (eventType == "collapsed") {
                node.setImageUrl('../images/topo/operation/folder.gif');
            }
            else if (eventType == "selected") {
                //NodeSelected(node);
                ;
            }
            ignoreEvents = false;
        }
        function setChildrenCheckBox(parentNode, value) {
            var childNodes = parentNode.getChildNodes();
            for (var i = 0; i < childNodes.length; i++) {
                var node = childNodes[i];
                node.setChecked(value);
                setChildrenCheckBox(node, value);
            }
            if (childNodes.length == 0) {

            }
        }
        function setParentCheckBox(node, value) {
            var parentNode = node.getParent();
            if (parentNode == null) return;
            parentNode.setChecked(value);
            if (!value || allSiblingChecked(parentNode))
                setParentCheckBox(parentNode, value);
        }
        function allSiblingChecked(node) {
            var nodes = node.getSiblingNodes();
            for (var i = 0; i < nodes.length; i++) {
                if (!nodes[i].getChecked())
                    return false;
            }
            return true;
        }
        function onChecked(treeview, node, eventType) {
            // judgeCheckBox(treeview, node);
            nodeEventHandler(treeview, node, eventType);
        }
        var videoParm = "";
        var sqlInsert = "";
        function btnOK() {
            judgeCheckBox();
            if (videoParm == "") {
                alert("请勾选视频通道!");
                return;
            }
            if (countTemp > 16) {
                var cz = countTemp - 16;
                alert("当前已经选中" + countTemp + "个视频通道！请去掉" + cz + "个通道才能正常显示！");
                return;
            }
            if (sqlInsert != "") {
                var del = "delete recordvideo where userisn='" + document.getElementById('hidUserisn').value + "'";
                var result = Topo_ImpMonitorIndex_SelTBS.excuteSql(del).value;
                sqlInsert = "  declare begin  " + sqlInsert + " end;";

            }
            var r = Topo_ImpMonitorIndex_SelTBS.excuteSql(sqlInsert).value;
            if (r) {
               /* alert('操作成功!');*/
                btnClose();
            }
            else {
                alert('操作失败!');
            }
        }      
       
        function judgeCheckBox() {

            countTemp = 0;
            videoParm = "";
            sqlInsert = "";
            if (nodeTree.getNodes().length > 0) {
                for (var l = 0; l < nodeTree.getNodes().length; l++) {

                    if (nodeTree.getNodes()[l].getChildNodes().length > 0) {
                        for (var nodeOne = 0; nodeOne < nodeTree.getNodes()[l].getChildNodes().length; nodeOne++) {
                            if (nodeTree.getNodes()[l].getChildNodes()[nodeOne].getChildNodes().length > 0) {
                                for (nodeTwo = 0; nodeTwo < nodeTree.getNodes()[l].getChildNodes()[nodeOne].getChildNodes().length; nodeTwo++) {
                                    if (nodeTree.getNodes()[l].getChildNodes()[nodeOne].getChildNodes()[nodeTwo].getChecked() == true) {
                                        var userisn = document.getElementById('hidUserisn').value;
                                        var ip = nodeTree.getNodes()[l].getChildNodes()[nodeOne].getChildNodes()[nodeTwo].getValue();
                                        var channel = nodeTree.getNodes()[l].getChildNodes()[nodeOne].getChildNodes()[nodeTwo].getText();
                                        channel = channel.substr(0, channel.length - 3);
                                        var name = nodeTree.getNodes()[l].getChildNodes()[nodeOne].getChildNodes()[nodeTwo].getAttribute('username');
                                        var pwd = nodeTree.getNodes()[l].getChildNodes()[nodeOne].getChildNodes()[nodeTwo].getAttribute('pwd');
                                        var roomid = nodeTree.getNodes()[l].getChildNodes()[nodeOne].getChildNodes()[nodeTwo].getAttribute('roomid');
                                        sqlInsert += "insert into recordvideo(userisn,ip,channel,username,pwd,roomid)values('" + userisn + "','" + ip + "','" + channel + "','" + name + "','" + pwd + "','" + roomid + "');";
                                        videoParm += ip + ":" + channel + ": ";
                                        countTemp++;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        function btnClose() {
          /*  window.opener.openVideo();//打开视频窗口*/
            window.close();
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div id="layout">
        <div id="layoutTitle" style="text-indent: 2em;">
            基站列表
        </div>
        <div id="layoutTree">
            <NineRays:FlyTreeView ID="ftvUnitTree" runat="server" Width ="98%"
                OnInitializedJavascript="flyNodeTree_onInitialized" OnNodeEventJavascript="onChecked"
                OnPopulateNodes="ftvUnitTree_PopulateNodes" ScrollTop="0" PostBackOnSelect="true">
            </NineRays:FlyTreeView>
        </div>
    </div>
    <div id="bottomBtn"> <input type ="button" value ="确定" onclick ="btnOK();" />
    <input type ="button" value ="关闭" onclick ="btnClose();" /></div>
   
    <input type="hidden" id="hidUserisn" runat="server" />
    </form>
</body>
</html>
